#! /bin/sh

confdir=`pwd`

# If the cache doesn't already exist, build it.

mcache=Makefile.local

if [ ! -f $mcache ]; then
    echo '## DO NOT EDIT THIS FILE DIRECTLY, EDIT THE configure SCRIPT' > $mcache
    echo '##' >> $mcache

    # Load the regular config settings.

    echo SRCDIR = `dirname $confdir` >> $mcache
    echo 'include $(SRCDIR)/config/Makefile.config' >> $mcache

    # Now any site-specific ones.

    if [ -f Makefile.site ]; then
        echo 'include $(SRCDIR)/config/Makefile.site' >> $mcache
    fi

    # Check for AFNI.

    AFNI=`which afni 2>/dev/null`
    if [ -n "$AFNI" ]; then
        echo "AFNI =" $AFNI >> $mcache
    fi

    # Set the compiler and linker options.

    echo 'include $(SRCDIR)/config/Makefile.opt' >> $mcache

    # Now we can do checks for things with the other variables set.

    if ! make -f Makefile.test test_gsl >/dev/null 2>/dev/null; then
        echo "OLD_GSL = 1" >> $mcache
    fi
    rm -f test_gsl.o test_gsl

    ## make >> $mcache
fi

echo $confdir
